package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.PraiseService;
import util.AjaxResult;
import vo.PraiseVo;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
@RequestMapping("/praise")
public class PraiseController {

    @Autowired
    PraiseService ps;

    //点赞/取消
    @RequestMapping("/tgPraise.do")
    @ResponseBody
    public AjaxResult tgPraise(HttpServletRequest req, PraiseVo praiseVo) {
        AjaxResult result = new AjaxResult(true, "success", null);
//        User u = (User) req.getSession().getAttribute(Constant.SESSION_USER);
        Integer user_id = 1;

        Date d = new Date();
        praiseVo.setComment_id(Integer.valueOf(req.getParameter("comment_id")));
        praiseVo.setUser_id(user_id);
        praiseVo.setCreate_date(d);

        if (ps.tgPraise(praiseVo)){
            result.setObj(true);//点赞成功
        }else {
            result.setObj(false);

        }
        return result;
    }
}
